home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / dynaweb.idb / usr / lib / Insight / data / config / preproc.dwc.z / preproc.dwc
Encoding:
Text File  |  1997-07-30  |  7.9 KB  |  217 lines

  1. ##======================================================================
  2. #
  3. # Request preprocessing script.
  4. #
  5. # This script gets control at the start of each request, after the URL
  6. # is parsed. We intend to use it to manage state between requests via
  7. # parameters on the URL (alternatively, we could use cookies, too, but
  8. # we're not sure how widely they are implemented now).
  9. #
  10. # Possible return values are:
  11. #   Proceed  (="Everything is swell, go to the next step"), 
  12. #   Exit     (="We have finished processing this request"),
  13. #   NoAction (="This URL was not meant for us"), and
  14. #   Abort    (="Something's wrong, please send an error to client")
  15. #
  16. # Notes:
  17. #   Use "exit" if you want to prevent any further processing
  18. #   from occurring. You should have already sent a response
  19. #   back to the client.
  20. #
  21. #   Use "abort" or "noaction"  only if you have not sent anything back
  22. #   to the client. "noaction" is sort of useless and should probably be
  23. #   avoided.
  24. #
  25. # IMPORTANT NOTE REGARDING TCL PROCS!
  26. # If you define any TCL procs, they must be defined from within a
  27. # the same dwScript where you run the proc, or in any dwScript that
  28. # was run before you try to call the proc. For sanity, we suggest that
  29. # you define most of your procs right up front in the preprocess script.
  30. #
  31. # We pick up parameters from the URL here. By convention, we use
  32. # two-letter codes:
  33. #
  34. #   cd - default collection TOC depth (number)
  35. #   td - default book TOC depth (number)
  36. #   hf - 0="no frames" 1="generate frames"
  37. #   ht - 0="no tables" 1="use tables"
  38. #   he - 0="no entities" 1="use entities"
  39. #
  40. ##=======================================================================
  41.  
  42. dwOnEvent PreProcessRequest HandlePreProcessRequestEvent
  43. dwOnEvent PostProcessRequest HandlePostProcessRequestEvent
  44.  
  45. dwScript HandlePreProcessRequestEvent {
  46.  
  47.    ## Load up the proc's!
  48.    ## NOTE: Full path for Windows NT & 95, where relative paths are broken.
  49.    dwSource [dwGetParam CONFIG_DIR]/procdef.dwc
  50.  
  51.    ##========================================================================
  52.    ## Main body starts from here
  53.    ##========================================================================
  54.  
  55.    ## Get our capability list
  56.    set  capabilities [dwSenseClientCapabilities]
  57.  
  58.    ##==========================================================================
  59.    ## Get the query form string (looks like ?DwebQueryForm=foo tacked on end
  60.    ## of URL). This is a special form of query that needs to have the
  61.    ## rest of the query parameters substituted into it.
  62.    ##==========================================================================
  63.  
  64.    set query_form [dwGetUrlQueryParam DwebQueryForm]
  65.    if {$query_form != ""} {
  66.       dwDelUrlQueryParam DwebQueryForm
  67.       set ok 1
  68.       while {$ok} {
  69.          set ok [regexp {\$([a-zA-Z0-9]+)} $query_form junk param]
  70.          if {$ok} {
  71.             set sub [dwGetUrlQueryParam $param]
  72.             set ok [regsub {\$([a-zA-Z0-9]+)} $query_form $sub query_form]
  73.          }
  74.      }
  75.      dwSetUrlQueryParams "DwebQuery=[dwUrlEncode $query_form]"
  76.    }
  77.  
  78.    # Do not put comments before switch selectors... it will cause them not
  79.    # to match
  80.    set locale [dwGetParam "dwServerLocale"]
  81.    switch -exact -- $locale {
  82.        "ja" {
  83.        # Japanese locale. Tries to send deal with SJIS with MS Windows
  84.        # machines, and EUC for UNIX boxes.
  85.        #
  86.        # Set the output encoding according to platform
  87.        if {[dwQueryCapability "platform" $capabilities] == "unix"} {
  88.            dwSetOutputEncoding "euc-jp"
  89.        } else {
  90.            dwSetOutputEncoding "shift-jis"
  91.        }
  92.        # Some browsers do not react well to certain values in the 
  93.            # charset parameter, so we tailor for that here.
  94.        if {[dwQueryCapability "broken_charset" $capabilities] == "1"} {
  95.            dwSetContentType "text/html"
  96.        } else {
  97.            dwSetContentType \
  98.           "text/html; charset=[dwMapEcmToIANA [dwGetOutputEncoding]]"
  99.        }
  100.        # The following will break with certain clients that don't stick
  101.        # to the conventions of sending back whatever the server sends
  102.        # to you. If clients actually provided proper labelling, there
  103.        # would be no guesswork here....
  104.        dwSet ActiveQuery [dwGetUrlQueryParam DwebQuery]
  105.        if {$ActiveQuery != ""} {
  106.            dwSet QueryEncoding [dwDetectStringEncoding $ActiveQuery "ja"]
  107.            if {[dwQueryCapability "platform" $capabilities] == "unix"} {
  108.            # Give priority to EUC for UNIX boxes
  109.            if {[lsearch $QueryEncoding "*euc-jp*"] != -1} {
  110.                dwSet ActiveQuery \
  111.                    [dwConvertEncoding $ActiveQuery "euc-jp"]
  112.            } else {
  113.                if {[lsearch $QueryEncoding "*shift-jis*"] != -1} {
  114.                dwSet ActiveQuery \
  115.                    [dwConvertEncoding $ActiveQuery "shift-jis"]
  116.                } else {
  117.                dwSet ActiveQuery \
  118.                    [dwConvertEncoding $ActiveQuery "euc-jp"]
  119.                }
  120.            }
  121.            } else {
  122.            # Give priority to SJIS for WINDOWS boxes
  123.            if {[lsearch $QueryEncoding "*shift-jis*"] != -1} {
  124.                dwSet ActiveQuery \
  125.                    [dwConvertEncoding $ActiveQuery "shift-jis"]
  126.            } else {
  127.                if {[lsearch $QueryEncoding "*euc-jp*"] != -1} {
  128.                dwSet ActiveQuery \
  129.                    [dwConvertEncoding $ActiveQuery "euc-jp"]
  130.                } else {
  131.                dwSet ActiveQuery \
  132.                    [dwConvertEncoding $ActiveQuery "shift-jis"]
  133.                }
  134.            }
  135.            }
  136.            dwSetQuery "$ActiveQuery"
  137.        }
  138.        }
  139.        "default" { 
  140.        # Locale for English or close relatives. This is the default
  141.        dwSetOutputEncoding "C"
  142.        dwSetContentType \
  143.            "text/html; charset=[dwMapEcmToIANA [dwGetOutputEncoding]]"
  144.        dwSet ActiveQuery [dwGetUrlQueryParam DwebQuery]
  145.        if {$ActiveQuery != ""} {
  146.            dwSet ActiveQuery [dwConvertEncoding $ActiveQuery "C"]
  147.            dwSetQuery "$ActiveQuery"
  148.        }
  149.        }
  150.    }
  151.  
  152.    ## chunking amount
  153.    dwSetPageMaxBytesHint 60000
  154.  
  155.    ## Get the state params
  156.    dwSet State__FramesSupport [dwQueryCapability "frames" $capabilities]
  157.    dwSet State__Frames   [dwGetUrlParam hf $State__FramesSupport]
  158.    dwSet State__Tables   [dwGetUrlParam ht [dwQueryCapability "tables" $capabilities]]
  159.    dwSet State__Entities [dwGetUrlParam he [dwQueryCapability "entities" $capabilities]]
  160.    dwSet State__TocDepth [dwGetUrlParam td [dwGetParam Default__TocDepth]]
  161.    dwSet State__CollTocDepth [dwGetUrlParam cd [dwGetParam Default__CollTocDepth]]
  162.  
  163.    ## Note that ContentStylesheet and TocStylesheet default to "default"
  164.    ## but are set in Collects.dwc and can be changed by the user to other
  165.    ## filenames
  166.    dwSet State__ContentStyle [dwGetUrlParam cs [dwGetParam ContentStylesheet]]
  167.    dwSet State__TocStyle [dwGetUrlParam ts [dwGetParam TocStylesheet]]
  168.  
  169.    ## These are request-specific state variables (probably should not
  170.    ## become cookies when we convert).
  171.    dwSet State__TocLoc [dwGetUrlParam tl ""]
  172.    dwSet State__UpdateOtherFrames [dwGetUrlParam uf 1]
  173.    dwSet State__NoNavigation [dwGetUrlParam nn 0]
  174.    dwSet State__NoAutoHit [dwGetUrlParam nh 0]
  175.  
  176.  
  177.    ##==========================================================================
  178.    ## Some random flags that need initializing per request.
  179.    ##==========================================================================
  180.  
  181.    dwSet DoReveal 0
  182.    dwSet TextStylesheet $State__ContentStyle
  183.    dwSet ShowingRootCollection 0
  184.  
  185.    dwCall dwMakeUrlParts
  186.  
  187.    if {[dwGet Service] == "infosrch"} {
  188.        dwSet State__UpdateOtherFrames 0
  189.    }
  190.  
  191.  return Proceed
  192. }
  193.  
  194. dwScript HandlePostProcessRequestEvent {
  195.    ## Nothing defined here!
  196. }
  197.  
  198.  
  199. ##======================================================================
  200. ##  Default "Collection View" script.
  201. ##  Called by the plug-in (C code) if there's no script in the URL
  202. ##======================================================================
  203. dwScript DefaultCollectionView {
  204.    dwCall Generic__CollectionView
  205. }
  206.  
  207.  
  208. ##======================================================================
  209. ##  Default "Book View" script.
  210. ##  Called by the plug-in (C code) if here's no script in the URL
  211. ##======================================================================
  212. dwScript DefaultBookView {
  213.    dwCall Generic__BookView
  214. }
  215.  
  216.  
  217.